function tst = kneu_test_smlr(R,TEST)

% Generates predictions using a trained multinomial regression model.
%
% tst = KNEU_TEST_SMLR(R,TESTPATS)
%
% SEE ALSO SMLR, TRAIN_SMLR

% License:
% ======================================================================
%
% This is part of the Princeton MVPA toolbox, released under the
% GPL. See http://www.csbmb.princeton.edu/mvpa for more
% information.
% 
% The Princeton MVPA toolbox is available free and
% unsupported to those who might find it useful. We do not
% take any responsibility whatsoever for any problems that
% you have related to the use of the MVPA toolbox.
%
% ======================================================================
% modified by CR, Dept. of Neurology, Magdeburg


w = R.w;

% Check if we need to add a fixed set of weights
if ~R.class_args.fit_all
  w(end,end+1) = 0; % add additional column of zeros
end

% Check if we need to add a fixed constant to the input
if R.class_args.constant
  TEST = [ones(size(TEST,1),1), TEST];
end

tst.test_w = w;

% Use logistic multinomial probability to make predictions
acts = exp(TEST * w)./ repmat(sum(exp(TEST * w),2),[1 size(w,2)]);
[maxProp, maxIdx]=max(acts,[],2);
tst.likelihoods=acts;
tst.prediction=R.classes(maxIdx);

